package com.example.demo.service.Impl;

import com.example.demo.common.domain.*;
import com.example.demo.mapper.EmployeeMapper;
import com.example.demo.mapper.RecordMapper;
import com.example.demo.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Service("es")
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    EmployeeMapper employeeMapper;
    @Autowired
    RecordMapper recordMapper;

    public Employee selectByPrimaryKey(Integer eid) {
        return employeeMapper.selectByPrimaryKey(eid);
    }

    @Override
    public void daka() {

    }

    @Override
    public List<Record> selectByEid(Integer eid) {
        return null;
    }

    @Override
    public List<Record> selectByEidDuring(Integer eid, Integer year, Integer month) {
        Calendar ca = Calendar.getInstance();
        ca.set(Calendar.YEAR,year);
        ca.set(Calendar.MONTH,month-1);
        ca.set(Calendar.DATE,1);

        Timestamp dateStart = new Timestamp(ca.getTimeInMillis());
        int lastDay = ca.getActualMaximum(Calendar.DAY_OF_MONTH);

        ca.set(Calendar.DATE,lastDay);
        Timestamp dateEnd = new Timestamp(ca.getTimeInMillis());

        RecordExample example = new RecordExample();

        example.createCriteria().andEidEqualTo(eid).andRstarttimeLessThan(dateStart).andRendtimeGreaterThan(dateEnd);
        return recordMapper.selectByExample(example);
    }

    @Override
    public void insertLeave(Leave_Record leave_record) {

    }

    @Override
    public void selectLeave() {

    }
}
